<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div>
        数量:
        <input type="text" id="num" value="1" oninput="changeNum()">
    </div>
    <div>
        单价:
        <input type="text" id="price" value="1" oninput="changePrice()">
    </div>
    <div>
        总计: <span id="total"></span>
    </div>
    <script>
        var num = document.getElementById("num")
        var price = document.getElementById("price")
        var total = document.getElementById("total");
        total.innerText =  Number(num.value)  * Number(price.value);

        function  changeNum(){
            var  numVal = Number(num.value);
            total.innerText =  numVal  * Number(price.value);
        }

        function  changePrice(){
            var  priceVal = Number(price.value);
            total.innerText =   Number(num.value)  * priceVal
        }
    </script>
</body>
</html>